package practice_05;

import Interface.Inter;

public class ParseInt {
    public static void main(String[] args) {
        String x = "123456789";
        System.out.println(parse_Int(x));
    }

    //自己写nextInt() 开头不能是0，最长10位，只能是数字

    public static int parse_Int(String x) {
        int Int_x = 0;
        if (!x.matches("[1-9]\\d{0,9}")) {
            System.out.println("输入错误，请重新输入!");
            parse_Int(x);
        } else {
            for (int i = 0; i < x.length(); i++) {
                int y = x.charAt(i) - '0';
                Int_x = Int_x * 10 + y;
            }
        }
        return Int_x;
    }
}
